<?php

namespace app\common\model;

use think\model\concern\SoftDelete;

class Product extends Model
{
    use SoftDelete;
    protected $name = 'product';
    protected $autoWriteTimestamp = true;

    //可搜索字段:商品名称、商品简介、关键字、是否门店自营
    protected $searchField = ['store_name', 'store_info', 'keyword','is_official'];

    // 属性获取器
    //是否启用获取器
    public function getStatusTextAttr($value, $data): string
    {
        return self::BOOLEAN_TEXT[$data['status']];
    }

    // 获取商品信息
    public static function getProductInfo($productId): array
    {
        return self::field('id, name, description, price, stock')
            ->findOrEmpty($productId)
            ->toArray();
    }
}